package cc.sunni.rabbitmqdelayedmessagedemo.controller;

import cc.sunni.rabbitmqdelayedmessagedemo.component.DelayedMessageSender;
import cc.sunni.rabbitmqdelayedmessagedemo.entity.Order;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

@RestController
public class MqController {
    public static final Logger log = LoggerFactory.getLogger(MqController.class);

    @Autowired
    private DelayedMessageSender sender;

    @PostMapping("/mq/{message}/{delay}")
    public String messageWithMQ(@PathVariable(value = "message") String message,
                                @PathVariable(value = "delay") Integer delay) {
        log.info("Send: " + message);
        Order order = new Order();
        order.setId(UUID.randomUUID().toString());
        order.setName("xx商城订单");
        order.setCreateTime(new Date());

        sender.send(message, delay);
        sender.send(order, delay);
        return "success";
    }

}